﻿using GamFi.Admin.API.Domain.Entities;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Metadata.Builders;

namespace GamFi.Admin.API.Persistence.Configurations;

public class PurchaseConfiguration: IEntityTypeConfiguration<Purchase>
{
    public void Configure(EntityTypeBuilder<Purchase> builder)
    {
        builder.HasKey(t => t.Id);

        builder.Property(t => t.Amount);

        builder.Property(t => t.Date);

        builder.Property(t => t.WalletId);

        builder.Property(t => t.TokenId);

        builder.HasOne(t => t.Wallet)
            .WithMany(w => w.Purchases)
            .HasForeignKey(t => t.WalletId)
            .OnDelete(DeleteBehavior.Cascade);
        
        builder.HasOne(t => t.Token)
            .WithMany(w => w.Purchases)
            .HasForeignKey(t => t.TokenId)
            .OnDelete(DeleteBehavior.Cascade);
    }
}